package org.csu.bbs.controller;

import org.csu.bbs.entity.Comment;
import org.csu.bbs.result.Result;
import org.csu.bbs.service.impl.CommentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class CommentController {
    @Autowired
    CommentServiceImpl commentServiceImpl;

    @CrossOrigin
    @PostMapping("api/comment")
    @ResponseBody
    public Result addComment(@RequestBody Comment comment){
        return commentServiceImpl.addComment(comment);
    }

    @CrossOrigin
    @GetMapping("api/comments/post/{id}")
    @ResponseBody
    public List<Comment> getComments(@PathVariable(value = "id") int id){
        return commentServiceImpl.getComments(id);
    }
}
